package com.devunion.bogdan.view.project.actions;

import com.devunion.bogdan.model.project.*;
import com.devunion.bogdan.view.project.PaperNode;
import com.devunion.bogdan.view.project.PageNode;
import com.devunion.bogdan.view.LibrarianEditor;

import javax.swing.*;
import java.awt.event.ActionEvent;

/**
 * @author Viktar Liaskovich
 */
public class RemovePageAction extends AbstractProjectAction {
    public boolean isApplicable(Paper e) {
        return false;
    }

    public void actionPerformed(ActionEvent e) {

        final JTree projectTree = LibrarianEditor.getInstance().getSelectedWorkspace().getProjectTreeBrowser().getProjectTree();
        PageNode selectedNode = (PageNode) projectTree.getSelectionPath().getLastPathComponent();

        Paper paper = ((PaperNode) selectedNode.getParent()).getUserObject();
        Page page = selectedNode.getUserObject();

        paper.removePage(page);
    }
}
